﻿using System.Text;
using System.Text.RegularExpressions;
using Kyoh.App.Crawler.Plugin;
using Kyoh.Lib.Plugin;
using System;
using System.Runtime.InteropServices;

namespace Crawler.Parser.ImePic
{
    [Guid("44902DA6-D573-4A71-9F33-99BE99AC4EC0")]
    public class ImePicParser : TypicalParser
    {
        public ImePicParser()
            : base(
                @"(?<uri>http://imepic\.jp/(?<contentId>\d{8}/\d+))",
                @"<div class=""headtitle"">(?<title>[^\<]+)</div>",
                @"",
                @"<img src=""(?<content>http://img\d+\.imepic\.jp/image/\d{8}/\d+\.\w+\?\w+)"" />",
                Encoding.UTF8)
        {
        }

        protected override string ContentIdPrefix
        {
            get { return "imepic"; }
        }

        protected override string GetExtension(string pageUri, string contentId, string title, string contentUri)
        {
            var match = Regex.Match(contentUri, @"http://img\d+\.imepic\.jp/image/\d{8}/\d+\.(?<ext>\w+)");
            if (match.Success)
                return match.Groups["ext"].Value;
            return "jpg";
        }

        public override string Author { get { return "kyoh"; } }
        public override string Description { get { return string.Empty; } }
        public override Uri Uri { get { return new Uri("http://kyoh.net/"); } }

        public override string Name { get { return "ImePic"; } }
    }
}
